home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Misc / InstallerNG / developer / gui / example / igui_CreateFileList.c < prev    next >
C/C++ Source or Header  |  1999-10-28  |  6KB  |  178 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. #include <string.h>
  6.  
  7. /********************************************************************
  8.  *
  9.  *  DESCRIPTION
  10.  *
  11.  */
  12.  
  13. /********************************************************************
  14.  *
  15.  *  STATIC
  16.  *
  17.  */
  18.  
  19. static BOOL walkdir_function(struct FileInfoBlock *, APTR);
  20.  
  21. static struct Node * __saveds find_node(struct List *, char *);
  22.  
  23. static APTR __asm __saveds list_construct_hook_fun(register __a0 struct Hook *, register __a1 struct FileInfoBlock *);
  24. static void __asm __saveds list_destruct_hook_fun(register __a1 struct FileInfoBlock *);
  25. static long __asm __saveds list_display_hook_fun(register __a1 struct FileInfoBlock *, register __a2 char **);
  26. static long __asm __saveds list_compare_hook_fun(register __a1 struct FileInfoBlock *, register __a2 struct FileInfoBlock *);
  27.  
  28. static struct Hook list_construct_hook = { { NULL, NULL }, (void *) list_construct_hook_fun, NULL, NULL };
  29. static struct Hook list_destruct_hook = { { NULL, NULL }, (void *) list_destruct_hook_fun, NULL, NULL };
  30. static struct Hook list_display_hook = { { NULL, NULL }, (void *) list_display_hook_fun, NULL, NULL };
  31. static struct Hook list_compare_hook = { { NULL, NULL }, (void *) list_compare_hook_fun, NULL, NULL };
  32.  
  33. /********************************************************************
  34.  *
  35.  *  EXTERN
  36.  *
  37.  */
  38.  
  39. /********************************************************************
  40.  *
  41.  *  PUBLIC
  42.  *
  43.  */
  44.  
  45. /********************************************************************
  46.  *
  47.  *  CODE
  48.  *
  49.  */
  50.  
  51. APTR __asm igui_CreateFileList(register __a0 APTR application,
  52.                                register __a1 char *dir,
  53.                                register __a2 struct FunctionEnvironment *localenv)
  54. {
  55.   #ifdef DEBUG
  56.   DEBUG_MAKRO
  57.   #endif
  58.  
  59.   {
  60.     APTR dirlist;
  61.     struct Application *app = (struct Application *) application;
  62.  
  63.     // set the localenv to the hook structure, such that the "list_construct_hook" has
  64.     // access to the localenv
  65.     list_construct_hook.h_Data = localenv;
  66.  
  67.     // create the list object (we cannot use a dirlist, because the list
  68.     // must have special attributes (see PATTERN/FILES/INFOS/CHOICES parameters)
  69.     // which cannot be satisfied by the simple mui dirlist
  70.     app->app_DirlistList = dirlist = ListviewObject,
  71.                                        MUIA_Background, MUII_ListBack,
  72.                                        MUIA_Frame, MUIV_Frame_InputList,
  73.                                        MUIA_Listview_MultiSelect, MUIV_Listview_MultiSelect_Default,
  74.                                        MUIA_Listview_List, ListObject,
  75.                                          MUIA_List_ConstructHook, &list_construct_hook,
  76.                                          MUIA_List_DestructHook, &list_destruct_hook,
  77.                                          MUIA_List_DisplayHook, &list_display_hook,
  78.                                          MUIA_List_CompareHook, &list_compare_hook,
  79.                                        End,
  80.                                      End;
  81.  
  82.     if (dirlist)
  83.     {
  84.       // walk through the complete dir and add the entries to the list
  85.       if (sav_DirWalk((char *) localenv->fe_Source, walkdir_function, dirlist))
  86.       {
  87.         // for walking through the list we have to set the "walk-marker"
  88.         app->app_DirlistWalker = MUIV_List_NextSelected_Start;
  89.  
  90.         // select all the files
  91.         DoMethod(dirlist, MUIM_List_Select, MUIV_List_Select_All, MUIV_List_Select_On, NULL);
  92.       }
  93.       else { /* should not happen */ }
  94.     }
  95.  
  96.     return (dirlist);
  97.   }
  98. }
  99.  
  100. /********************************************************************/
  101.  
  102. // give the fib to the list
  103. static BOOL __saveds walkdir_function(struct FileInfoBlock *fib, APTR dirlist)
  104. {
  105.   DoMethod(dirlist, MUIM_List_InsertSingle, fib, MUIV_List_Insert_Sorted);
  106.   return(TRUE);
  107. }
  108.  
  109. static APTR __asm __saveds list_construct_hook_fun(register __a0 struct Hook *hook, register __a1 struct FileInfoBlock *fib)
  110. {
  111.   APTR fibcpy = NULL;
  112.   BOOL accept = TRUE;
  113.  
  114.   // the localenv of the function
  115.   struct FunctionEnvironment *localenv = hook->h_Data;
  116.  
  117.   //
  118.   if (localenv->fe_All) { }
  119.  
  120.   //
  121.   else if (!sav_IsListEmpty(&(localenv->fe_Choices)))
  122.   {
  123.     accept = (long) find_node((struct List *) &(localenv->fe_Choices), (char *) &(fib->fib_FileName));
  124.   }
  125.  
  126.   //
  127.   else if (localenv->fe_Pattern)
  128.   {
  129.     accept = sav_MatchPatternNoCase((STRPTR) localenv->fe_Pattern, (char *) &(fib->fib_FileName));
  130.     if (accept == -1) { accept = 0; }
  131.   }
  132.  
  133.   // if not filtered yet, we have to gon on with checking
  134.   if (localenv->fe_Fonts && accept) { accept = !sav_FontFile((char *) &(fib->fib_FileName)); }
  135.   if (localenv->fe_Infos && accept) { accept = !sav_InfoFile((char *) &(fib->fib_FileName)); }
  136.   if (localenv->fe_Files && accept) { if (fib->fib_EntryType != ST_FILE) { accept = FALSE; } }
  137.  
  138.   // if we have to accept the file, clone the fib and put this
  139.   // fib to the mui list
  140.   if (accept && (fibcpy = sav_AllocVec(sizeof(struct FileInfoBlock), MEMF_ANY|MEMF_CLEAR)))
  141.   {
  142.     CopyMem(fib, fibcpy, sizeof(struct FileInfoBlock));
  143.   }
  144.  
  145.   //
  146.   return(fibcpy);
  147. }
  148.  
  149. static void __asm __saveds list_destruct_hook_fun(register __a1 struct FileInfoBlock *fib)
  150. {
  151.   sav_FreeVec(fib);
  152. }
  153.  
  154. static long __asm __saveds list_display_hook_fun(register __a1 struct FileInfoBlock *fib, register __a2 char **array)
  155. {
  156.   *array = (char *) &(fib->fib_FileName);
  157.   return(0);
  158. }
  159.  
  160. static long __asm __saveds list_compare_hook_fun(register __a1 struct FileInfoBlock *fib1, register __a2 struct FileInfoBlock *fib2)
  161. {
  162.   return(stricmp((char *) &(fib1->fib_FileName), (char *) &(fib2->fib_FileName)));
  163. }
  164.  
  165. static struct Node * __saveds find_node(struct List *list, char *name)
  166. {
  167.   struct Node *node = sav_GetHead(list);
  168.  
  169.   while(node)
  170.   {
  171.     if (!Stricmp(name, node -> ln_Name)) { return(node); }
  172.     node = sav_GetSucc(node);
  173.   }
  174.  
  175.   //
  176.   return(NULL);
  177. }
  178.